//
//  ViewController.m
//  Runtime+NSCoding
//
//  Created by isoftstone on 2018/9/20.
//  Copyright © 2018年 isoftstone. All rights reserved.
//

#import "ViewController.h"
#import "Person.h"
#import <objc/runtime.h>
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    unsigned int count;
    Ivar* vars = class_copyIvarList([Person class], &count);
    Ivar var = vars[0];
    const char* name = ivar_getName(var);
    NSString* objc_name = [NSString stringWithUTF8String:name];
    NSLog(@"%@", objc_name);
    

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)writeToFileClick:(id)sender {
    NSString* path =  NSTemporaryDirectory();
    path = [path stringByAppendingPathComponent:@"kai.kk"];
    NSLog(@"%@", path);
    Person* p = [[Person alloc] init];
    p.name = @"zhangsan";
    p.age = @"18";
    [NSKeyedArchiver  archiveRootObject:p toFile:path];
}
- (IBAction)readFromFileClick:(id)sender {
    NSString* path =  NSTemporaryDirectory();
    path = [path stringByAppendingPathComponent:@"kai.kk"];
    Person* p = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
    NSLog(@"%@", p.name);
    NSLog(@"%@", p.age);
    
}

@end
